package com;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Enumeration;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionContext;

import com.connection.jdbconnection;

public class ForgetPassword extends HttpServlet {

	
	
	
	Statement st=null;
	ResultSet rs=null;
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
doPost(request, response);
		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		 HttpSession session = request.getSession();
		String fname=request.getParameter("fname");
		System.out.println(fname);
		String lname=request.getParameter("lname");
		System.out.println(lname);
		String email=request.getParameter("email");
		System.out.println(email);
		if(fname !=null && lname !=null && email !=null){
			try {
				jdbconnection db=new jdbconnection();
				st=db.jdbConnection();
				String sql="select * from register where firstName ='" + fname +"' and lastName='"+ lname +"' and email='"+email+"'";
				System.out.println(sql);
				 System.out.println(sql);
		            rs=st.executeQuery(sql);
		            
		       
		            
		         
		            if (rs.next()) {

		                         String userName=rs.getString("userName");
		                         String password=rs.getString("password");
		                         
		                         System.out.println(userName);
		                         System.out.println(password);
		                         
		                        
		                         session.setAttribute("userName",userName);
		                         session.setAttribute("password",password);
		             request.getRequestDispatcher("GetForgetPassword.jsp").forward(request, response);
		             
		             st.close();
		            }
		            else {
		    			session.setAttribute("error", new Object());
		    			response.sendRedirect("GetForgetPassword.jsp");
		    			return;
		    			
		    			
		    		}
			
			
		}catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
		}
		
        
		
		
		
	}

	

}
